package com.eazy.lksy.reptile;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import com.eazy.lksy.reptile.dao.AreaDao;
import com.eazy.lksy.reptile.dao.LineDao;
import com.eazy.lksy.utils.JsonKsy;
import com.eazy.lksy.utils.Unit;

public class CatchCityInfo {

	static List<String> cityList = new ArrayList<String>(Arrays.asList("beijing_city","shanghai_city","guangzhou","shenzhen"));
	
	public static void main(String[] args) {
		
		for(int i =0; i< cityList.size(); i++) {
			String requestUrl = "http://lh.qunar.com/render/hotelLocationCategory.jsp?t=1454045168040&cityurl="+cityList.get(i)+"&__jscallback=XQScript_10";
			String data = Unit.getHtmlContent(requestUrl);
			String detail = JsonKsy.parseObj(data, "details");
			String[] area =  JsonKsy.parseArr(JsonKsy.parseObj(detail, "行政区"),"value");
			
			int key = getKey(cityList.get(i));
			
			//AreaDao.addAea(area[0],key);

			String[] line = JsonKsy.parseArr(JsonKsy.parseObj(detail, "地铁线路"), "type","value");
			
			int number = 0;
			for(int j =0 ; j< line.length; j++) {
				if(j % 2 == 0) {
					number = LineDao.addLineName(line[j],key);
				} else {
					LineDao.addLine(line[j],number);
				}
				
			}
			
		}
	}
	
	// 判断城市id
	public static int getKey(String data) {
		int number = 0;
		switch (data) {
		case "beijing_city":
			number = 1;
			break;
		case "shanghai_city":
			number = 2;
			break;
		case "guangzhou":
			number = 3;
			break;
		case "shenzhen":
			number = 4;
			break;
		default:
			break;
		}
		return number;
	}
	

}
